/*
THIS FILE IS PART OF THE >>ADRENALIN-3D-GRAFIC-ENGINE<<
for latest info visit http://www.creative-games.de

Copyright (c) 2008-2009 by Marco Schneider

This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License (LGPL) as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

*/

#ifndef __ADL_DIRECTX10_DEVICE_H__
#define __ADL_DIRECTX10_DEVICE_H__

#pragma once

#include <windows.h>
#include <d3d10_1.h>
#include <d3dx10.h>

#include "../Singleton.h"
#include "../Log.h"
#include "../Math/Math.h"
#include "../../interfaces/IDevice.h"

//// include the Direct3D Library file
#pragma comment (lib, "d3d10.lib")
#pragma comment (lib, "d3dx10.lib")

namespace Adrenalin 
{
	//create a basic vertex container
	struct vertex
	{
		D3DXVECTOR3 pos;
		D3DXVECTOR4 color;

		vertex( D3DXVECTOR3 p, D3DXVECTOR4 c )
		{
			pos = p;
			color = c;
		}
	};

	class DirectX10Device  : public Singleton<Adrenalin::DirectX10Device>, public IDevice
	{
		friend class Singleton<Adrenalin::DirectX10Device>;
	private:
		int							_resolutionX;
		int							_resolutionY;
		IDXGISwapChain*				_swapChain;
		ID3D10Device*				_d3DDevice;
		ID3D10RenderTargetView*		_renderTargetView;
		D3D10_VIEWPORT				_viewPort;
		//Test:
		ID3D10Buffer*				_pVertexBuffer;
		ID3D10InputLayout*			_pVertexLayout;
		D3DXMATRIX                  _viewMatrix;
		D3DXMATRIX                  _projectionMatrix;
		ID3D10RasterizerState*		_pRS;
		ID3D10Effect*				_pBasicEffect;
		ID3D10EffectTechnique*		_pBasicTechnique;
		ID3D10EffectMatrixVariable* _pViewMatrixEffectVariable;
		ID3D10EffectMatrixVariable* _pProjectionMatrixEffectVariable;
		ID3D10EffectMatrixVariable* _pWorldMatrixEffectVariable;

	private:
		DirectX10Device();
	public:
		EResult Init(HWND hWnd, int x, int y, bool windowed);
		void BeginRender();
		void EndRender();
		void Close();
		void SetPerspectiveFovLH( Math::Vector3<float>& eye, Math::Vector3<float>& at, Math::Vector3<float>& up, float near, float far );

		//TestArea
		void RenderVertex();
		void LoadEffectFile();
		void CreateVertex();
	};
}

#endif